/* UTF8 Encoding */
/*-----------------------------------------------------------------------
|                            FILE DESCRIPTION                           |
-----------------------------------------------------------------------*/
/*----------------------------------------------------------------------
  - File name     : stm32_flash.h
  - Author        : liuzhihua (liuzhihuawy@163.com)
  - Update date   : 2024.06.08
  - Brief         : stm32 flash
  - Version       : v0.1
-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------
|                               UPDATE NOTE                             |
-----------------------------------------------------------------------*/
/**
 * Update note:
 * ------------   ---------------   ----------------------------------
 *     Date            Author                      Note
 * ------------   ---------------   ----------------------------------
 *  2024.06.08       liuzhihua                 Create file
 ***/

#ifndef __STM32_FLASH_H__
#define __STM32_FLASH_H__

/*-----------------------------------------------------------------------
|                               INCLUDES                                |
-----------------------------------------------------------------------*/
#include "stm32f0xx.h"

#ifdef __cplusplus
extern "C"
{
#endif
/*-----------------------------------------------------------------------
|                                DEFINES                                |
-----------------------------------------------------------------------*/
#define CHIP_FLASH_BASE_ADDR    FLASH_BASE      // Flash start address
#define CHIP_FLASH_PAGE_SIZE    FLASH_PAGE_SIZE // Flash一页长度(Byte)
//       关闭/打开  CPU中断
#define STM32_FLASH_ENABLE_INTERRUPT  __enable_irq()
#define STM32_FLASH_DISABLE_INTERRUPT __disable_irq()

#define CHIP_OS_EN_INTERRUPT() STM32_FLASH_ENABLE_INTERRUPT
#define CHIP_OS_DI_INTERRUPT() STM32_FLASH_DISABLE_INTERRUPT

/*-----------------------------------------------------------------------
|                                  API                                  |
-----------------------------------------------------------------------*/

HAL_StatusTypeDef stm32_flash_rewrite_page(int page, uint8_t *p_buffer, int size);

HAL_StatusTypeDef stm32_flash_erase_page(int startPage, int endPage);

HAL_StatusTypeDef stm32_flash_write_page(int page, uint8_t *p_buffer, int size);

HAL_StatusTypeDef stm32_flash_read_page(int page, uint8_t *buffer, int size);

#ifdef __cplusplus
}
#endif
#endif
